package services

import (
	"micro-bbs/initialize"
	"micro-bbs/libs"
	"micro-bbs/mqueue"
	"micro-bbs/repositories"
)

/*
	提供关于RabbitMQ服务

	作者名称：leixiaotian 创建时间：20211124
*/
type RabbitmqInterfaceService interface {
	PushLoginLog(id int64) (interface{},error)    //推送登录日志MQ
	PushConfirmPost(id int64) (interface{},error) //推送发帖确认MQ
	PullLoginLog(number int)                      //拉取登录日志MQ
}

//初始化对象函数
func NewRabbitmqService() RabbitmqInterfaceService {
	return &rabbitmqService{
		bbsUserService:          repositories.NewBbsUser(),
		rabbitMqService: 		 mqueue.NewRabbitService(),
	}
}

type rabbitmqService struct {
	bbsUserService 			    repositories.BbsUserInterface           //社区会员服务
	rabbitMqService 			mqueue.RabbitInterfaceService           //rabbitMQ服务
}

//推送登录日志MQ
func (this *rabbitmqService) PushLoginLog(id int64) (interface{}, error) {
	userInfo, err := this.bbsUserService.SelectInfo(id)
	initialize.IrisLog.Infof("[mq服务-userInfo数据]-[%s]", libs.StructToJson(userInfo))
	if err != nil {
		initialize.IrisLog.Errorf("[mq服务-获取帖子信息失败]-[%s]", err.Error())
		return 3006, err
	}
	this.rabbitMqService.PushLoginLog(userInfo)
	return true, nil
}

//推送发帖确认MQ
func (this *rabbitmqService) PushConfirmPost(id int64) (interface{}, error) {
	initialize.IrisLog.Infof("[mq服务-recordId]-[%d]", id)
	this.rabbitMqService.PushUserPost(id)
	return true, nil
}

//拉取登录日志MQ
func (this *rabbitmqService) PullLoginLog(number int) {
	this.rabbitMqService.PullLoginLog(number)
	return
}